@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layui-form layuiadmin-card-header-auto">
                <!--region 搜索部分-->
                <!--endregion-->
            </div>
            <div class="layui-card-body">
                <table id="recharge-app-list" lay-filter="recharge-app-list"></table>
                <script type="text/html" id="toolbar-recharge-app-list">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="createFunc">添加</button>
                    </div>
                </script>
                <script type="text/html" id="tool-recharge-app-list">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detailFunc"><i class="layui-icon layui-icon-release"></i>详情</a>
                    <a class="layui-btn layui-btn-xs" lay-event="moreFunc">更多 <i class="layui-icon layui-icon-down"></i></a>
                </script>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'system'], function () {
            // 定义操作列表
            var actionList = {
                // 创建
                createFunc: function () {
                    layui.system.iframeLayer({
                        sourceWindow: window,
                        targetWindow: 'top',
                        title: '添加',
                        content: layui.setter.mvcLink + '/recharge/admin_app/create',
                        btn: ['确定', '取消'],
                        yes: function (layerIndex, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-create');
                            submit.click();
                        }
                    });
                },
                // 更新
                updateFunc: function (object) {

                },
                // 详情
                detailFunc: function (object) {

                },
                // 删除
                deleteFunc: function (object) {
                    console.log('删除：', data)
                },
                // 配置管理
                configRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/recharge/admin_config/retrieve?app_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '配置管理');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 功能管理
                handleRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/recharge/admin_handle/retrieve?app_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '功能管理');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 更多方法
                moreFunc: function (object) {
                    console.log('对象：', object)
                    layui.dropdown.render({
                        elem: this,
                        show: true,
                        align: 'right',
                        data: [{
                            id: 'recharge-app-update',
                            title: '编辑',
                            action: 'updateFunc'
                        }, {
                            id: 'recharge-config-retrieve',
                            title: '配置管理',
                            action: 'configRetrieveFunc'
                        }, {
                            id: 'recharge-handle-retrieve',
                            title: '功能管理',
                            action: 'handleRetrieveFunc'
                        }, {
                            id: 'recharge-app-delete',
                            title: '删除',
                            action: 'deleteFunc'
                        }],
                        click: function (dropdownData, dropdownElement) {
                            return actionList[dropdownData.action] ? actionList[dropdownData.action].call(this, object) : '';
                        }
                    });
                },
            };
            // 渲染列表
            layui.table.render({
                elem: '#recharge-app-list',
                toolbar: '#toolbar-recharge-app-list',
                url: layui.setter.apiLink + '/recharge/admin_app/retrieve',
                parseData: function (result) {
                    return {
                        code: result.code == 1 ? 0 : 1,
                        msg: result.msg,
                        count: result.data.total,
                        data: result.data.items
                    }
                },
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: 80, title: 'ID', sort: true},
                    {field: 'name', title: '名称'},
                    {field: 'app_id', title: 'AppID'},
                    {fixed: 'right', width: 160, title: '操作', align: 'center',  toolbar: '#tool-recharge-app-list'}
                ]],
                page: true,
                limit: 10,
                limits: [10, 15, 20, 25, 30],
                text: '数据加载异常！'
            });
            // 工具操作
            layui.table.on('toolbar(recharge-app-list)', function (object) {
                return actionList[object.event] ? actionList[object.event].call(this, object) : '';
            });
            // 列表操作
            layui.table.on('tool(recharge-app-list)', function (object) {
                return actionList[object.event] ? actionList[object.event].call(this, object) : '';
            });
        });
    </script>
@endsection